//
//  SISSMortgageLoansBankShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/4/11.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSMortgageLoansBankShowViewController.h"
#import "SISSProgressWebViewController.h"

@interface SISSMortgageLoansBankShowViewController ()

@end

@implementation SISSMortgageLoansBankShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseID = @"ID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.textColor = MAIN_TEXT_COLOR;
        cell.textLabel.numberOfLines = 0;
        CGFloat margin = 8.0;
        [cell.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.contentView).offset(0.5 * margin);
            make.left.right.equalTo(cell.contentView).offset(margin);
            make.right.equalTo(cell.contentView).offset(-margin);
            make.bottom.equalTo(cell.contentView).offset(-2 * margin);
        }];
    };
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSDictionary *dict = self.dataSource[indexPath.section];
    if ([dict[@"cellType"] integerValue] == 3) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:dict[@"imageName"]];
        [cell.contentView addSubview:imageView];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(cell.contentView);
            make.bottom.right.equalTo(cell.contentView);
        }];
    }
    cell.accessoryType = ([dict[@"cellType"] integerValue] == 2) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
    cell.textLabel.text = dict[@"text"];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dict = self.dataSource[indexPath.section];
    if ([dict[@"cellType"] integerValue] == 2) {
        SISSProgressWebViewController *vc = [[SISSProgressWebViewController alloc] init];
        vc.title = dict[@"text"];
        vc.url = dict[@"url"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    NSDictionary *dict = self.dataSource[section];
    UILabel *label = [UILabel yyr_labelWithText:dict[@"title"] fontSize:17 textColor:MAIN_TEXT_COLOR];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(16);
        make.centerY.equalTo(view);
    }];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
     NSDictionary *dict = self.dataSource[section];
    return dict[@"title"] ? 44 : 1;
}

/// 取消tableView组头悬停
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 44;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
